import os
import sys
from datetime import datetime
import pytz
from loguru import logger

from utils.filePathTools import EnsureFolders, NoDuplicateFile


class LogsRecorder:
    log_path = './data/logs/'
    # log_name = sys.argv[0].split(".")[0].split("/")[-1] + ".log" # 获取运行脚本名
    log_name = os.path.basename(sys.argv[0]).split(".")[0]
    log_path_name = log_path + log_name
    newFile = False

    def InitLogger(self, log_path='', log_name=log_name):
        if len(log_path.strip()) > 1:
            self.log_path = EnsureFolders(log_path)
        self.log_name = log_name
        self.log_path_name = NoDuplicateFile(self.log_path, self.log_name, '.log')
        print('logger :', self.log_path_name)
        id = log = logger.add(self.log_path_name, rotation="10 MB", retention="60 days", compression="zip",
                              enqueue=True)
    # def b_function1(x):
    #     try:
    #         return 1 / x
    #     except ZeroDivisionError:
    #         logger.exception("exception!!!")
    #
    # b_function1(0)
    # logger.remove(id)
# logRecorder =LogRecorder()
# logRecorder.InitLogger()
# logger.debug('this is a debug message')
# logger.debug('i am debug message')
# logger.info('i am info message')
# logger.error('i am error message')
# logger.success('i am success message')
